|
1
|
|
|
/** |
|
2
|
|
|
Copyright (C) 2018-2020 KANOUN Salim |
|
3
|
|
|
This program is free software; you can redistribute it and/or modify |
|
4
|
|
|
it under the terms of the Affero GNU General Public v.3 License as published by |
|
5
|
|
|
the Free Software Foundation; |
|
6
|
|
|
This program is distributed in the hope that it will be useful, |
|
7
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
8
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
9
|
|
|
Affero GNU General Public Public for more details. |
|
10
|
|
|
You should have received a copy of the Affero GNU General Public Public along |
|
11
|
|
|
with this program; if not, write to the Free Software Foundation, Inc., |
|
12
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
const UppyCsvPlugin = class UppyCsvPlugin extends Uppy.Core.Plugin { |
|
16
|
|
|
|
|
17
|
|
|
constructor (uppy, opts) { |
|
18
|
|
|
super(uppy, opts) |
|
19
|
|
|
this.id = opts.id |
|
20
|
|
|
this.type = opts.type |
|
21
|
|
|
this.checkCSV = this.checkCSV.bind(this) |
|
22
|
|
|
|
|
23
|
|
|
this.patientId = opts.patientId |
|
24
|
|
|
this.studyDate = new Date(opts.studyDate) |
|
25
|
|
|
this.suvLo = opts.suvLo |
|
26
|
|
|
this.suvHigh = opts.suvHigh |
|
27
|
|
|
this.useSuv = opts.useSuv |
|
28
|
|
|
this.useCT = opts.useCT |
|
29
|
|
|
this.notify = opts.notify |
|
30
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
checkCSV(filesIDs){ |
|
34
|
|
|
|
|
35
|
|
|
let file = this.uppy.getFile(filesIDs[0]) |
|
36
|
|
|
|
|
37
|
|
|
let csvParser = new PetCtCSVParser(file.data) |
|
38
|
|
|
|
|
39
|
|
|
return csvParser.parseCSV().then( () => { |
|
40
|
|
|
|
|
41
|
|
|
let checkPatientIdentity = csvParser.checkAcquisition(this.patientId, this.studyDate) |
|
42
|
|
|
let checkThreshold = csvParser.checkTMTVThreshold(this.suvLo) |
|
43
|
|
|
|
|
44
|
|
|
this.notify({ |
|
45
|
|
|
Tmtv : csvParser.getTmtvValue(), |
|
46
|
|
|
suvLo : csvParser.getSuvLow(), |
|
47
|
|
|
checkPatientIdentity : checkPatientIdentity, |
|
48
|
|
|
checkThreshold : checkThreshold |
|
49
|
|
|
}) |
|
50
|
|
|
|
|
51
|
|
|
return (checkPatientIdentity && checkThreshold) |
|
52
|
|
|
}).then((resultCheck)=> { |
|
53
|
|
|
if(!resultCheck) this.uppy.removeFile(file.id) |
|
54
|
|
|
else this.uppy.emit('preprocess-complete', file.id) |
|
55
|
|
|
}).catch( () => { |
|
56
|
|
|
this.notify({ |
|
57
|
|
|
otherError : 'Error Reading CSV' |
|
58
|
|
|
}) |
|
59
|
|
|
this.uppy.removeFile(file.id) |
|
60
|
|
|
}) |
|
61
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
install () { |
|
65
|
|
|
this.uppy.addPreProcessor(this.checkCSV) |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
uninstall () { |
|
69
|
|
|
this.uppy.removePreProcessor(this.checkCSV) |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|